{% extends "base.html" %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0">编辑安全事故</h4>
                </div>
                <div class="card-body">
                    <form method="POST">
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label">事故编号</label>
                                <input type="text" class="form-control" value="{{ incident.incident_no }}" readonly>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">状态</label>
                                <select class="form-select" name="status" required>
                                    <option value="open" {% if incident.status == 'open' %}selected{% endif %}>待处理</option>
                                    <option value="investigating" {% if incident.status == 'investigating' %}selected{% endif %}>调查中</option>
                                    <option value="resolved" {% if incident.status == 'resolved' %}selected{% endif %}>已解决</option>
                                    <option value="closed" {% if incident.status == 'closed' %}selected{% endif %}>已关闭</option>
                                </select>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label">产品名称</label>
                                <input type="text" class="form-control" name="product_name" value="{{ incident.product_name }}" required>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">批次号</label>
                                <input type="text" class="form-control" name="batch_number" value="{{ incident.batch_number }}" required>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label">事故类型</label>
                                <select class="form-select" name="incident_type" required>
                                    <option value="contamination" {% if incident.incident_type == 'contamination' %}selected{% endif %}>污染</option>
                                    <option value="temperature" {% if incident.incident_type == 'temperature' %}selected{% endif %}>温度异常</option>
                                    <option value="damage" {% if incident.incident_type == 'damage' %}selected{% endif %}>产品损坏</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">严重程度</label>
                                <select class="form-select" name="severity" required>
                                    <option value="low" {% if incident.severity == 'low' %}selected{% endif %}>轻微</option>
                                    <option value="medium" {% if incident.severity == 'medium' %}selected{% endif %}>中等</option>
                                    <option value="high" {% if incident.severity == 'high' %}selected{% endif %}>严重</option>
                                    <option value="critical" {% if incident.severity == 'critical' %}selected{% endif %}>危急</option>
                                </select>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="form-label">发生时间</label>
                                <input type="datetime-local" class="form-control" name="occurrence_date" 
                                    value="{{ incident.occurrence_date.strftime('%Y-%m-%dT%H:%M') }}" required>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">发现时间</label>
                                <input type="datetime-local" class="form-control" name="discovery_date" 
                                    value="{{ incident.discovery_date.strftime('%Y-%m-%dT%H:%M') }}" required>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">发生地点</label>
                            <input type="text" class="form-control" name="location" value="{{ incident.location }}" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">事故描述</label>
                            <textarea class="form-control" name="description" rows="4" required>{{ incident.description }}</textarea>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">应急处理措施</label>
                            <textarea class="form-control" name="immediate_action" rows="3">{{ incident.immediate_action }}</textarea>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">处理结果</label>
                            <textarea class="form-control" name="resolution" rows="3">{{ incident.resolution }}</textarea>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">备注</label>
                            <textarea class="form-control" name="notes" rows="3">{{ incident.notes }}</textarea>
                        </div>
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">保存更改</button>
                            <a href="{{ url_for('safety.incident_list') }}" class="btn btn-secondary">返回列表</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 